<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" ></meta>
	<#include "../common.html" />
</head>
<body>
<div  class="easyui-panel" data-options="fit:true,border:false">
	<ul id="viewPermissionTree" class="easyui-tree" data-options="checkbox:true"/>
</div>
	<script>
		var rid = ${id};
		viewPermissionTree = $('#viewPermissionTree').tree({
			url : '/easyui/role/permissionTree?rid='+rid,
			width:175,
			panelHeight:150,
			required:true,
			multiple:true,
			cascadeCheck:false,
			method:'get'//,
			// onLoadSuccess:function(node,data){
				// var treeValuesArray = treeValues.split(",");
				// for(var i =0; i < treeValuesArray.length;i++){
				// 	var node = viewPermissionTree.tree('find',treeValuesArray[i]);
				// 	if(node){
				// 		var isLeaf = viewPermissionTree.tree('isLeaf', node.target);
				// 		if(isLeaf){
				// 			viewPermissionTree.tree('check', node.target);
				// 		}
				// 	}
				// }
			// }
		});
		function submitPermission($permissionDialog,$pjq) {
			var checkednodes = viewPermissionTree.tree('getChecked');
			var indeterminatenodes = viewPermissionTree.tree('getChecked', 'indeterminate');
			var rolePermission = [];
			for (var i = 0; i < checkednodes.length; i++) {
				rolePermission.push({"rid":rid, "pid":checkednodes[i].id})
			}
			for (var i = 0; i < indeterminatenodes.length; i++) {
				rolePermission.push({"rid":rid, "pid":indeterminatenodes[i].id})
			}
			if(rolePermission.length == 0){
				$pjq.messager.alert('提示', '请选择权限！', 'info');
				return;
			}
			$.ajax({
				url: "/admin/permission/modifyRolePermission",
				data:  JSON.stringify(rolePermission),
				contentType: "application/json; charset=utf-8",
				type: "POST",
				dataType: 'json',
				success: function(result){
					if (result.success) {
						$pjq.messager.alert('提示', result.msg, 'info',function(r){
							$permissionDialog.dialog('destroy');
						});
					} else {
						$pjq.messager.alert('错误',result.msg,'error');
					}
				}
			});
		}
	</script>
</body>
</html>